﻿using System;
using RestSharp.Serializers;

namespace Phorest.Voucher.Models
{
    [SerializeAs(Name = "voucher")]
    internal class Voucher
    {
        // ---------------------------------------------------------------------------------------------

        [SerializeAs(Name = "serial")]
        public string Serial { get; private set; }

        // ---------------------------------------------------------------------------------------------

        [SerializeAs(Name = "issueDate")]
        public string IssueDate { get; private set; }

        // ---------------------------------------------------------------------------------------------

        [SerializeAs(Name = "expiryDate")]
        public string ExpiryDate { get; private set; }

        // ---------------------------------------------------------------------------------------------

        [SerializeAs(Name = "originalBalance")]
        public decimal OriginalBalance { get; private set; }

        // ---------------------------------------------------------------------------------------------

        [SerializeAs(Name = "creatingBranchRef")]
        public string CreatingBranchRef { get; private set; }

        // ---------------------------------------------------------------------------------------------

        internal Voucher(VoucherRequest request, SerialNumber serial)
        {
            if (serial == null)
                throw new ArgumentNullException("serial");

            Serial = serial.Serial;
            IssueDate = request.IssueDate.Date.ToString("yyyy-MM-dd");
            ExpiryDate = request.ExpiryDate.Date.ToString("yyyy-MM-dd");
            OriginalBalance = request.OriginalBalance;

            if (request.Branch != null)
                CreatingBranchRef = string.Format(Configuration.BranchUrnFormat, request.Branch.BranchId);
        }

        // ---------------------------------------------------------------------------------------------
    }
}